package cn.sunlight.mm.wx.service.impl;

import cn.sunlight.framework.annotation.HmComponent;
import cn.sunlight.mm.database.SqlSessionUtils;
import cn.sunlight.mm.pojo.Course;
import cn.sunlight.mm.pojo.Dict;
import cn.sunlight.mm.wx.dao.CourseDao;
import cn.sunlight.mm.wx.dao.DictDao;
import cn.sunlight.mm.wx.service.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author sunlight
 * @description:
 * @date 2021/5/28
 * @Version v1.0
 */
@HmComponent("commonService")
@Slf4j
public class CommonServiceImpl implements CommonService {

    @Override
    public Dict getCityInfoByName(String cityName) {
        log.info("getCityInfoByName,cityName:{}",cityName);
        SqlSession sqlSession = SqlSessionUtils.openSession();
        DictDao dictDao=sqlSession.getMapper(DictDao.class);
        Dict city=dictDao.selectByCityName(cityName);
        sqlSession.close();
        return city;
    }

    @Override
    public List<Dict> getCityList(Integer tag) {
        log.info("getCityList,tag:{}",tag);
        SqlSession sqlSession = SqlSessionUtils.openSession();
        DictDao dictDao=sqlSession.getMapper(DictDao.class);
        List<Dict> dictList=dictDao.selectCityListByTag(tag);
        sqlSession.close();
        return dictList;
    }

    @Override
    public List<Course> findCourseList() {
        log.info("getCourseList");
        SqlSession sqlSession = SqlSessionUtils.openSession();
        CourseDao courseDao=sqlSession.getMapper(CourseDao.class);
        List<Course> courseList=courseDao.selectCourseList();
        sqlSession.close();
        return courseList;
    }
}
